-
Notifications
You must be signed in to change notification settings - Fork 53
Add strongly-typed external events with DurableEventAttribute #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…pport Co-authored-by: YunchuWang <[email protected]>
Co-authored-by: YunchuWang <[email protected]>
Co-authored-by: YunchuWang <[email protected]>
|
@copilot resolve the conflicts |
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…into copilot/add-strongly-typed-events
|
@copilot update samples\AzureFunctionsApp to use event source generation too |
|
@copilot update pr description to follow .github/PULL_REQUEST_TEMPLATE.md |
- Added ApprovalOrchestrator.cs demonstrating DurableEventAttribute usage in Azure Functions - Includes ApprovalEvent record with [DurableEvent] attribute - ApprovalOrchestrator shows waiting for events with generated WaitForApprovalEventAsync - Added HTTP triggers to start orchestration and send approval events - Added NotifyApprovalRequired activity - Included APPROVAL_README.md with usage documentation - Added Abstractions project reference to access DurableEventAttribute - Fixed generator to not emit AddAllGeneratedTasks when only events are present - All 41 generator tests passing Co-authored-by: YunchuWang <[email protected]>
Updated AzureFunctionsApp with strongly-typed event source generation in commit b495a87. Added ApprovalOrchestrator.cs demonstrating:
See samples/AzureFunctionsApp/APPROVAL_README.md for usage details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for strongly-typed external events in Durable Task orchestrations through a new DurableEventAttribute and source generator extension. Developers can now annotate event types with [DurableEvent] to automatically generate type-safe WaitFor{EventName}Async extension methods for TaskOrchestrationContext, eliminating the need for string literals and providing compile-time safety similar to existing orchestrator and activity support.
Key Changes:
- Introduced
DurableEventAttributefor annotating event types - Extended source generator to detect and generate strongly-typed event wait methods
- Added comprehensive unit tests and sample applications demonstrating the feature
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Abstractions/DurableEventAttribute.cs |
New attribute for marking event types with optional custom event names |
src/Generators/DurableTaskSourceGenerator.cs |
Extended generator to detect DurableEventAttribute and generate WaitFor{EventName}Async methods; added System.Threading using statement |
test/Generators.Tests/ClassBasedSyntaxTests.cs |
Added 3 unit tests covering basic records, explicit names, and namespaced events |
test/Generators.Tests/Utils/TestHelpers.cs |
Added System.Threading to generated using statements for test support |
samples/EventsSample/Events.cs |
Defines example event types with DurableEventAttribute |
samples/EventsSample/Tasks.cs |
Demonstrates orchestrators using generated event methods |
samples/EventsSample/Program.cs |
Sample entry point showing approval and data processing workflows |
samples/EventsSample/README.md |
Documentation explaining the feature with usage examples |
samples/EventsSample/EventsSample.csproj |
Project configuration referencing source generator |
samples/AzureFunctionsApp/ApprovalOrchestrator.cs |
Azure Functions example with HTTP triggers and event handling |
samples/AzureFunctionsApp/AzureFunctionsApp.csproj |
Added Abstractions project reference for DurableEventAttribute |
Microsoft.DurableTask.sln |
Added EventsSample project to solution |
halspang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be in the right direction, just a few questions.
| /// It is used specifically by build-time source generators to generate type-safe methods for waiting | ||
| /// for external events in orchestrations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also call SendEvent from contexts, do you want to have a strongly typed method for that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot do it for sendevent as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added strongly-typed SendEvent methods in commit 6c4db99.
For each event annotated with [DurableEvent], the generator now creates both:
WaitFor{EventName}Async()- to receive eventsSend{EventName}()- to send events to other orchestration instances
Example for [DurableEvent("ApprovalEvent")]:
context.SendApprovalEvent(targetInstanceId, new ApprovalEvent(true, "John"));- Added AddEventSendMethod to generate Send{EventName} extension methods
- Generated methods provide type-safe way to send events between orchestrations
- Updated all 3 event unit tests to verify SendEvent generation
- All 41 generator tests passing
- AzureFunctionsApp builds successfully with new methods
Co-authored-by: YunchuWang <[email protected]>
I can't see the screenshot - could you describe what issue or change you'd like me to address? |
update to support source generating sendevent on the context object as well, dont forget updating samples and tests |
The SendEvent feature is already implemented in commit 6c4db99! The generator now creates both methods for each
All 3 unit tests have been updated to verify both methods are generated correctly, and all 41 tests are passing. Example generated code for public static void SendApprovalEvent(
this TaskOrchestrationContext context,
string instanceId,
ApprovalEvent eventData)
{
context.SendEvent(instanceId, "ApprovalEvent", eventData);
}The samples currently demonstrate using the client's |
|
@copilot .Select((x, _) => (x.Right, x.Left.Left.Left, x.Left.Left.Right, x.Left.Right)); this is confusing to read, can you add comments to explain |
- Added inline comments explaining the nested tuple structure from .Combine() - Clarified what each part of the unpacking represents (Compilation, Tasks, Events, Functions) - Improves code readability and maintainability for future developers Co-authored-by: YunchuWang <[email protected]>
Added explanatory comments in commit fc99572. The comments now explain:
|








Implementation Plan for Strongly-Typed Events
DurableEventAttributein the Abstractions projectDurableTaskSourceGeneratorto detectDurableEventAttributeand generate strongly-typedWaitFor{EventName}Asyncextension methods forTaskOrchestrationContextSend{EventName}extension methods for sending events between orchestrationsSummary
Successfully implemented strongly-typed external events feature with source generation support for both waiting and sending events. All 41 tests pass successfully.
Key Features:
WaitFor{EventName}AsyncandSend{EventName}extension methods onTaskOrchestrationContextGenerated Methods:
For an event annotated with
[DurableEvent("ApprovalEvent")]:WaitFor method:
Send method:
EventsSample (Console App):
AzureFunctionsApp Sample:
ApprovalEventrecord with[DurableEvent]attributeWaitForApprovalEventAsync()methodNotifyApprovalRequiredactivityOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.